<!-- view_cart.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>查看购物车</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }
        .container {
            max-width: 800px;
            margin: 20px auto;
            padding: 0 20px;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        ul {
            list-style-type: none;
            padding: 0;
        }
        li {
            background-color: #fff;
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        li:hover {
            background-color: #f0f0f0;
        }
        a {
            color: #007bff;
            text-decoration: none;
            margin-left: 10px;
        }
        a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>购物车</h1>
    <ul id="cart-items"></ul>
    <a href="#" onclick="clearCart()">清空购物车</a>
</div>
<script>
        function displayCart() {
            var cart = JSON.parse(localStorage.getItem('cart')) || [];
            var cartList = document.getElementById('cart-items');
            cartList.innerHTML = '';
            cart.forEach(function(item) {
                var li = document.createElement('li');
                li.textContent = item.name + ' - ￥' + item.price + ' ';
                var removeLink = document.createElement('a');
                removeLink.href = '#';
                removeLink.textContent = '移除';
                removeLink.onclick = function() {
                    removeFrom购物车('"+item.name+"', "+item.price+"); return false;
            };
                li.appendChild(removeLink);
                cartList.appendChild(li);
            });
            }
        function clearCart() {
        localStorage.removeItem('cart');
        displayCart();
    }

    displayCart();
</script>
</body>
</html>